package org.surthi.app.bank.web.ajax;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
import org.springframework.orm.hibernate3.SessionHolder;
import org.springframework.transaction.support.TransactionSynchronizationManager;

public abstract class AjaxBase {

	private SessionFactory sessionFactory;
	
	
	protected void setUp(){		
		Session session = SessionFactoryUtils.getSession(sessionFactory, true);
		TransactionSynchronizationManager.bindResource(sessionFactory,new SessionHolder(session));
	}

	protected void tearDown() {
		SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.
												unbindResource(sessionFactory);
		SessionFactoryUtils.closeSession(holder.getSession());
	}

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}


	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
}
